<?php
require 'isok.php';
require 'dbcon.php';
require 'posts.php';
$page=isset($_GET['page'])?$_GET['page']:1;
$pagesize=15;
$num=getnum();
$maxpage=ceil($num/$pagesize);
$postdata=getpage($page,$pagesize);
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Posts &laquo; Admin</title>
  <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href="../assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href="../assets/css/admin.css">
  <script src="../assets/vendors/nprogress/nprogress.js"></script>
</head>
<body>
  <script>NProgress.start()</script>

  <div class="main">
   <?php include 'shang.php';?>
    <div class="container-fluid">
      <div class="page-title">
        <h1>所有文章</h1>
        <a href="post-add_html.php" class="btn btn-primary btn-xs">写文章</a>
      </div>
      <!-- 有错误信息时展示 -->
      <!-- <div class="alert alert-danger">
        <strong>错误！</strong>发生XXX错误
      </div> -->
      <div class="page-action">
        <!-- show when multiple checked -->
        <a class="btn btn-danger btn-sm" href="javascript:;" style="display: none">批量删除</a>
        <form class="form-inline">
          <select name="" class="form-control input-sm">
            <option value="">所有分类</option>
            <option value="">未分类</option>
          </select>
          <select name="" class="form-control input-sm">
            <option value="">所有状态</option>
            <option value="">草稿</option>
            <option value="">已发布</option>
          </select>
          <button class="btn btn-default btn-sm">筛选</button>
        </form>
        <ul class="pagination pagination-sm pull-right">
        <li><a href="">当前第<?php echo $page;?>页/共<?php echo $maxpage;?>页</a></li>  
        <li><a href="?page=1">首页</a></li>
        <li><a href="?page=<?php echo $page==1?1:$page-1;?>">上一页</a></li>
         <?php 
          for($i=1;$i<=$maxpage;$i++)
          {
             echo "<li><a href='?page={$i}'>{$i}</a></li>";
          }
          ?>
          <li><a href="?page=<?php echo $page==$maxpage?$maxpage:$page+1;?>">下一页</a></li>
          <li><a href="?page=<?php echo $maxpage?>">尾页</a></li>
        </ul>
      </div>
      <table class="table table-striped table-bordered table-hover">
        <thead>
          <tr>
            <th class="text-center" width="40"><input type="checkbox"></th>
            <th>标题</th>
            <th>作者</th>
            <th>分类</th>
            <th class="text-center">发表时间</th>
            <th class="text-center">状态</th>
            <th class="text-center" width="100">操作</th>
          </tr>
        </thead>
        <tbody>
             <?php 
                foreach($postdata as $v)
                {
              ?>
          <tr>
            <td class="text-center"><input type="checkbox"></td>
            <td><?php echo $v['title' ]?></td>
            <td><?php echo $v['nickname' ]?></td>
            <td><?php echo $v['name' ]?></td>
            <td class="text-center"><?php echo $v['created' ]?></td>
            <td class="text-center">
                <?php 
                  if ($v['status']=='published')echo "已发布";
                  if ($v['status']=='drafted')echo "草稿";
                ?>
            </td>
            <td class="text-center">
              <a href="post_update.php?id=<?php echo $v['id' ]?>" class="btn btn-default btn-xs">编辑</a>
              <a href="javascript:;" class="btn btn-danger btn-xs" onclick="if(confirm('确定删除吗？')) location.href='postsdel.php?id=<?php echo $v['id' ]?>'" >删除</a>
            </td>
          </tr>
          <?php
                }
                ?>
<!--          <tr>
            <td class="text-center"><input type="checkbox"></td>
            <td>随便一个名称</td>
            <td>小小</td>
            <td>潮科技</td>
            <td class="text-center">2016/10/07</td>
            <td class="text-center">已发布</td>
            <td class="text-center">
              <a href="javascript:;" class="btn btn-default btn-xs">编辑</a>
              <a href="javascript:;" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
          <tr>
            <td class="text-center"><input type="checkbox"></td>
            <td>随便一个名称</td>
            <td>小小</td>
            <td>潮科技</td>
            <td class="text-center">2016/10/07</td>
            <td class="text-center">已发布</td>
            <td class="text-center">
              <a href="javascript:;" class="btn btn-default btn-xs">编辑</a>
              <a href="javascript:;" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>-->
        </tbody>
      </table>
    </div>
  </div>

  <?php include 'left.php';?>

  <script src="../assets/vendors/jquery/jquery.js"></script>
  <script src="../assets/vendors/bootstrap/js/bootstrap.js"></script>
  <script>NProgress.done()</script>
</body>
</html>